import  {wxuuid} from  '@/utils/uuid.js'
import  {getDateYYYYMMDDHHMISS} from  '@/utils/date.js'
import config from '@/config/config.js'
/**
 * 获取 header 
 */
export function getHeaders(){
	return {
		'app-id': config.AppId,
		'transaction-id': wxuuid(),
		'req-time': getDateYYYYMMDDHHMISS(),
		'sign': '1234567',
		'user-id': '-1',
		'X-Requested-With':'XMLHttpRequest',
		 "store-id": uni.getStorageSync('STAFF_USER_INFO') ?JSON.parse(uni.getStorageSync('STAFF_USER_INFO')).storeId :"",
		// #ifndef H5
		cookie: '_java110_token_=' + uni.getStorageSync('token')
		// #endif
	};
};

function request({ url, method, data }) {
  return new Promise((resolve, reject) => {
    uni.request({
      url:config.baseUrl+url,
      method,
      data,
      header: getHeaders(),
      success: response => {
        const res = response.data
		 resolve(res)
      },
      fail: (err) => {
	    reject(err)
      }
    })
  })
}

export default request
